import Vue from 'vue'
import Vuex from 'vuex'
import Config from '@/public/config'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    hasLogin: false,
    userInfo: null,
    jsLoader:[]
  },
  mutations: {
    login(state, userInfo, loginFromStorage) {
      userInfo.realname = decodeURIComponent(userInfo.realname);
      state.userInfo = userInfo || null;
      state.hasLogin = true;
      if (!loginFromStorage) {
        localStorage.setItem('jUser', JSON.stringify(userInfo));
      }
    },
    logout(state) {
      state.userInfo = null;
      state.hasLogin = false;
      state.userCurRole = -2;
      localStorage.removeItem('jUser');
    },
    setJsLoader(state,jsUrl) {
      state.jsLoader.push(jsUrl)
    },
  }
})

export default store